package Text35;

import java.util.*;
public class Main {
    static int N = 50010;
    static PII[] p = new PII[N];
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int w=scanner.nextInt();
            int s=scanner.nextInt();
            p[i]=new PII(w+s,w);
        }
        Arrays.sort(p,0,n);
        int res=-Integer.MAX_VALUE;
        int sum=0;
        for (int i = 0; i < n; i++) {
            int w=p[i].b;
            int s=p[i].a-w;
            res=Math.max(res,sum-s);
            sum+=w;
        }
        System.out.println(res);
    }
}
class PII implements Comparable<PII>{
    public int a,b;

    public PII(int a, int b) {

        this.a= a;
        this.b = b;
    }

    @Override
    public int compareTo(PII o) {
        return Integer.compare(a,o.a);
    }
}